module TrackChanges
  module ActiveRecord

    # Enables auditing of all changes to an ActiveRecord model. Sets up an
    # around filter that will create an Audit for the models <tt>changes</tt>
    # attribute.
    #
    # In addition, this will also define a <tt>attr_accessor</tt> for <tt>current_user</tt>.
    def track_changes
      send :include, TrackChanges::CurrentUser
      send :include, TrackChanges::Changes

      self.class_eval do
        has_many :audits, :as => :audited

        around_update TrackChanges::AroundUpdate
      end
    end
  end
end

ActiveRecord::Base.extend TrackChanges::ActiveRecord
